# -*- coding: UTF-8 -*-
##########################################
## 文件名称：
## 功能说明：
## 
## 
## 创建人： 
## 创建时间：
## 修改：
##
##
##########################################

import os
import shutil
import pandas as pd
import xlwt
import datetime

def getDataframe(file_name):##'data.csv'
    df = pd.read_csv(file_name, encoding='gbk')
    
    temp_list = df['date']
    date_list=[]
    for e in temp_list:
        date_str = datetime.datetime.strptime(e ,'%Y/%m/%d').strftime('%Y-%m-%d')
        date_list.append(date_str)
    df['date']=date_list
        
    return df

def df_pivot(dataDF,pivotJson=None):
    columns_list = dataDF.columns.to_list()
    
    if pivotJson is None:
        pivotJson = {}
        pivotJson["index"] = columns_list[0]
        pivotJson["columns"] = columns_list[1]
        pivotJson["values"] = columns_list[2]
        
    dataDF = dataDF.pivot(index=pivotJson["index"], columns=pivotJson["columns"], values=pivotJson["values"])
    dataDF.index.model_name= 'date'

        
#     dataDF = dataDF.fillna(method='ffill') 
    
    return dataDF
    
##获取沪深300因子
def get_hs300():
    pass
    file_name="factor_data_hs300_sd.csv"
    dataDF = getDataframe(file_name)
    
    tempDF = df_pivot(dataDF,pivotJson=None)
    cols=["ZJ_ISPO","GZ_PEG","GZ_Erating","HW_IRS1Y","GZ_EROE","QX_FUNDPROP","GZ_EPB","QX_Investor_Confi","QX_Invstor_Confi_Global","QX_Invstor_Confi_GZ","HG_Rd"]
    tempDF['GZ_Erating']=''
    tempDF=tempDF.ix[:,cols]
    tempDF.to_csv("factor_hs300_sd.csv")
    

if __name__ == '__main__':
    pass

#     hs300 = pd.read_csv("FCST_HS300.csv",encoding='gbk')
#     
#     temp_list = hs300['Unnamed: 0']
#     date_list=[]
#     for e in temp_list:
#         date_str = datetime.datetime.strptime(e ,'%Y/%m/%d').strftime('%Y-%m-%d')
#         date_list.append(date_str)
#         
#         
# #     date_list.append("2020-06-19")
#         
#     dateDf = pd.DataFrame({'date': date_list})
#     dateDf=dateDf.set_index(['date'])
     
#     file_name="factor_data_hs300_sd.csv"
#     dataDF = getDataframe(file_name)
#     tempDF = df_pivot(dataDF,pivotJson=None)
#     cols=["ZJ_ISPO","GZ_PEG","GZ_Erating","HW_IRS1Y","GZ_EROE","QX_FUNDPROP","GZ_EPB","QX_Investor_Confi","QX_Invstor_Confi_Global","QX_Invstor_Confi_GZ","HG_Rd"]
#     tempDF['GZ_Erating']=''
#     tempDF=tempDF.ix[:,cols]
#     tempDF.to_csv("factor_hs300_sd.csv")
#     
# 
#     new_df = pd.concat([dateDf,tempDF], axis=1)
# #     new_df = new_df.fillna(method='ffill') 
# 
#     new_df.to_csv("bbb.csv")
#     
#     new_df2 = new_df.join(dateDf,how='inner') 
# # 
# #     cols=["ZJ_ISPO","GZ_PEG","GZ_Erating","HW_IRS1Y","GZ_EROE","QX_FUNDPROP","GZ_EPB","QX_Investor_Confi","QX_Invstor_Confi_Global","QX_Invstor_Confi_GZ","HG_Rd"]
# #     new_df2['GZ_Erating']=''
# #     new_df2=new_df2.ix[:,cols]
# 
#     new_df2.to_csv("ccc.csv")
    
    get_hs300();
    
    
    
